package com.niuxiaofa.newlaw.Activity;

import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Base.BaseActivity;
import com.niuxiaofa.newlaw.Base.BaseFragment;
import com.niuxiaofa.newlaw.Bean.RankingBean;
import com.niuxiaofa.newlaw.Network.LawUniversalPresenter;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.Constant;
import com.niuxiaofa.newlaw.Tools.GlideUtils;
import com.niuxiaofa.newlaw.Tools.RecyclerViewHelp;
import com.niuxiaofa.newlaw.Tools.ToActivityUtil;
import com.niuxiaofa.newlaw.adapter.AwardRankingAdapter;
import com.niuxiaofa.newlaw.adapter.LawRankingAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import www.linwg.org.lib.LCardView;


/**
 * 普法排行
 */
public class LawUniversalRankingActivity extends BaseActivity implements LawUniversalPresenter.interface_getPopularityRankList {


    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;

    @BindView(R.id.today)
    LCardView today;


    @BindView(R.id.reward)
    LCardView reward;


    LawRankingAdapter lawRankingAdapter;

    List<RankingBean.DataDTO> newsList = new ArrayList<>();


    @BindView(R.id.user_img1)
    ImageView user_img1;


    @BindView(R.id.user_img2)
    ImageView user_img2;


    @BindView(R.id.user_img3)
    ImageView user_img3;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_law_ranking;
    }

    @Override
    public void initData() {

        setTitle("普法排行榜");

        LawUniversalPresenter.getPopularityRankList("1", this);

        lawRankingAdapter = new LawRankingAdapter(newsList, e -> {
        });

        RecyclerViewHelp.setRecycler(recyclerview, 0).setAdapter(lawRankingAdapter);


        today.setOnClickListener(e -> {
            LawUniversalPresenter.getPopularityRankList("1", this);
            reward.setCardBackgroundColor(Color.parseColor("#FF000000"));
            today.setCardBackgroundColor(Color.parseColor("#FFF4C66F"));

        });

        reward.setOnClickListener(e -> {
            LawUniversalPresenter.getPopularityRankList("2", this);
            reward.setCardBackgroundColor(Color.parseColor("#FFF4C66F"));
            today.setCardBackgroundColor(Color.parseColor("#FF000000"));
        });

    }

    @Override
    public void getResponse(RankingBean u) {
        if (u.getCode() == 1) {
            newsList.clear();
            newsList.addAll(u.getData());
            lawRankingAdapter.notifyDataSetChanged();
            if (newsList.size() > 3) {
                GlideUtils.loadUserImg(getContext(), newsList.get(0).getHeader(), user_img1);
                GlideUtils.loadUserImg(getContext(), newsList.get(1).getHeader(), user_img2);
                GlideUtils.loadUserImg(getContext(), newsList.get(2).getHeader(), user_img3);
            }

        }
    }
}
